/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License
 * (http://www.opensource.org/licenses/lgpl-license.php)
 *
 * For further information go to http://www.fredck.com/FCKeditor/ 
 * or contact fckeditor@fredck.com.
 *
 * fck_actions.js: Actions called by the toolbar.
 *
 * Authors:
 *   Frederico Caldeira Knabben (fckeditor@fredck.com)
 */
 
function decCommand(cmdId, cmdExecOpt)
{
	var status = objContent.QueryStatus(cmdId) ;
	
	if ( status != DECMDF_DISABLED && status != DECMDF_NOTSUPPORTED )
	{
		if (cmdExecOpt == null) cmdExecOpt = OLECMDEXECOPT_DODEFAULT ;
		objContent.ExecCommand(cmdId, cmdExecOpt) ;
	}
	objContent.focus() ;
}

function docCommand(command)
{
	objContent.DOM.execCommand(command) ;
	objContent.focus();
}

function doStyle(command)
{
	alert("Not implemented: " + command.value) ;
}

function doFormatBlock(combo)
{
	if (combo.value == null || combo.value == "")
		objContent.ExecCommand(DECMD_SETBLOCKFMT, OLECMDEXECOPT_DODEFAULT, 'Normal');
	else
		objContent.ExecCommand(DECMD_SETBLOCKFMT, OLECMDEXECOPT_DODEFAULT, combo.value);
	
	objContent.focus();
}

function doFontName(combo)
{
	if (combo.value == null || combo.value == "")
	{
		// TODO: Remove font name attribute.
	}
	else
		objContent.ExecCommand(DECMD_SETFONTNAME, OLECMDEXECOPT_DODEFAULT, combo.value);
	
	objContent.focus();
}

function doFontSize(combo)
{
	if (combo.value == null || combo.value == "")
	{
		// TODO: Remove font size attribute (Now it works with size 3. Will it work forever?)
		objContent.ExecCommand(DECMD_SETFONTSIZE, OLECMDEXECOPT_DODEFAULT, 3);
	}
	else
		objContent.ExecCommand(DECMD_SETFONTSIZE, OLECMDEXECOPT_DODEFAULT, parseInt(combo.value));
	
	objContent.focus();
}

function dialogImage()
{
	var html = showModalDialog("dialog/fck_image.html", window, "dialogWidth:400px;dialogHeight:380px;help:no;scroll:no;status:no");
	// The response is the IMG tag HTML
	if (html) insertHtml(html) ;
	objContent.focus() ;
}

function dialogTable()
{
	showModalDialog("dialog/fck_table.html", window, "dialogWidth:350px;dialogHeight:210px;help:no;scroll:no;status:no");
	objContent.focus() ;
}

// insertHtml(): Insert HTML at the current document position.
function insertHtml(html)
{
	objContent.DOM.selection.clear() ;
	objContent.DOM.selection.createRange().pasteHTML(html) ; 
}

function foreColor()
{
	var color = showModalDialog( "dialog/fck_selcolor.html", "","dialogWidth:370px;dialogHeight:240px;help:no;scroll:no;status:no" );
	if (color) objContent.ExecCommand(DECMD_SETFORECOLOR,OLECMDEXECOPT_DODEFAULT, color) ;
	objContent.focus();
}

function backColor()
{
	var color = showModalDialog( "dialog/fck_selcolor.html", "","dialogWidth:370px;dialogHeight:240px;help:no;scroll:no;status:no" );
	if (color) objContent.ExecCommand(DECMD_SETBACKCOLOR,OLECMDEXECOPT_DODEFAULT, color) ;
	objContent.focus();
}

function insertSpecialChar()
{
	var html = showModalDialog("dialog/fck_specialchar.html", window, "dialogWidth:400px;dialogHeight:250px;help:no;scroll:no;status:no");
	if (html) insertHtml(html) ;
	objContent.focus() ;
}

function about()
{
	showModalDialog("dialog/fck_about.html", null, "dialogWidth:460px;dialogHeight:290px;help:no;scroll:no;status:no");
}
